import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/guide/index')
  },
  {
    path: '/document',
    component: () => import('@/views/document/index'),
    children: [
      {
        path: '/document/outline',
        component: () => import('@/views/document/modules/Outline')
      }, {
        path: '/document/detail',
        component: () => import('@/views/document/modules/Detail')
      }
    ]
  },
  {
    path: '/exercises',
    component: () => import('@/views/exercises/index'),
    children: [
      {
        path: '/exercises/chapter',
        component: () => import('@/views/exercises/modules/Chapter')
      }, {
        path: '/exercises/chapter/collect',
        component: () => import('@/views/exercises/modules/ChapterCollect')
      }, {
        path: '/exercises/simulation',
        component: () => import('@/views/exercises/modules/Simulation')
      }, {
        path: '/exercises/simulation/collect',
        component: () => import('@/views/exercises/modules/SimulationCollect')
      }
    ]
  },
  {
    path: '/manage',
    component: () => import('@/views/manage/index'),
    children: [
      {
        path: '/manage/content',
        component: () => import('@/views/manage/modules/Content')
      },
      {
        path: '/manage/question',
        component: () => import('@/views/manage/modules/Question')
      }
    ]
  },
  {
    path: '/about',
    component: () => import('@/views/about/index')
  }
]

const createRouter = () => new Router({
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes,
  mode: 'history'
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
